<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="员工">
          <el-input v-model="queryParam.qry_str" placeholder="姓名或工号"></el-input>
        </el-form-item>
        <el-form-item label="角色">
          <el-input v-model="queryParam.qry_role" placeholder="角色关键字"></el-input>
        </el-form-item>
        <el-form-item label="公司名称">
          <el-input v-model="queryParam.qry_orgname" placeholder="角色关键字"></el-input>
        </el-form-item>
        <el-form-item label="位置">
          <el-select v-model="queryParam.qry_position" clearable filterable>
            <el-option v-for="item in codeModel.positionList" :key="item.code" :label="item.name" :value="item.code" />
          </el-select>
        </el-form-item>
        <el-form-item label="级别">
          <el-select v-model="queryParam.qry_recordlevel" clearable filterable>
            <el-option v-for="item in codeModel.recordlevelList" :key="item.code" :label="item.name" :value="item.code" />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" :isDisplayExport="false" :isDisplayAdd="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn">
        <el-button class="filter-item" type="primary" icon="el-icon-download" @click="openAddDialog('editCompanyForm')">新增公司级</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-download" @click="openAddDialog('editRoleForm')">新增角色级</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-download" @click="openAddDialog('editPersonalForm')">新增个人级</el-button>
      </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="selection" width="55px" fixed="left"></el-table-column>
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="username" label="姓名" width="120px" sortable="custom" sort-by="username" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="usercode" label="工号" width="120px" sortable="custom" sort-by="usercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="disprolecode" label="角色" width="150px" sortable="custom" sort-by="rolecode" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="disporgcode" label="公司名称" width="300px" sortable="custom" sort-by="orgcode" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcomponentid" label="组件名称" width="150px" sortable="custom" sort-by="componentid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="priority" label="优先级" width="120px" sortable="custom" sort-by="priority" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="dispposition" label="位置" width="150px" sortable="custom" sort-by="position" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="disprecordlevel" label="级别" width="120px" sortable="custom" sort-by="recordlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column> -->
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column> -->
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
      <tl-edit-company ref="editCompanyForm" @refresh="doRefresh"></tl-edit-company>
      <tl-edit-personal ref="editPersonalForm" @refresh="doRefresh"></tl-edit-personal>
      <tl-edit-role ref="editRoleForm" @refresh="doRefresh"></tl-edit-role>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlEditCompany from './editCompany'
import tlEditPersonal from './editPersonal'
import tlEditRole from './editRole'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { checkPermission } from '@tapui/utils/permission'
export default {
  name: 'mpmDataBoardCustomizeRecord',
  mixins: [mixin_list],
  components: { tlEdit, tlEditCompany, tlEditPersonal, tlEditRole },
  data() {
    return {
      description: '数据看板自定义记录表-列表查询',
      urlPrefix: '/mpm/dataBoardCustomizeRecord/',
      url: {
        queryCodeList: '/mpm/dataBoardCustomizeRecord/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode',
        sord: 'asc'
      }
    }
  },
  methods: {
    doRowDbClick(row, column, event) {
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            if (row.rolecode != null) {
              this.openEditDialog('editRoleForm', row[this.$refs.mainTable.rowKey])
            } else if (row.orgcode != null) {
              this.openEditDialog('editCompanyForm', row[this.$refs.mainTable.rowKey])
            } else {
              this.openEditDialog('editPersonalForm', row[this.$refs.mainTable.rowKey])
            }
          } else {
            if (row.rolecode != null) {
              this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
            } else if (row.orgcode != null) {
              this.openViewDialog('editCompanyForm', row[this.$refs.mainTable.rowKey])
            } else {
              this.openViewDialog('editPersonalForm', row[this.$refs.mainTable.rowKey])
            }
          }
        } else {
          if (row.rolecode != null) {
            this.openEditDialog('editRoleForm', row[this.$refs.mainTable.rowKey])
          } else if (row.orgcode != null) {
            this.openEditDialog('editCompanyForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openEditDialog('editPersonalForm', row[this.$refs.mainTable.rowKey])
          }
        }
      } else if (this.rowDbClickActionType === 'view') {
        if (row.rolecode != null) {
          this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
        } else if (row.orgcode != null) {
          this.openViewDialog('editCompanyForm', row[this.$refs.mainTable.rowKey])
        } else {
          this.openViewDialog('editPersonalForm', row[this.$refs.mainTable.rowKey])
        }
      }
    }
  }
}
</script>

<style scoped></style>

